<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link href="../file/images/dianmin.png" rel="shortcut icon" type="image/x-icon"/>
    <link rel="stylesheet" type="text/css" href="../file/css/gwc.css"/>
    <title>确认订单</title>
</head>

<body>
<div class="top">
    <img src="../file/images/dianmin.png" width="300px" height="100px">
    <div class="header-info">
        <div class="login-info" id="login_info">
            <!--用户-->
        </div>
        <div class="person-info">
            <span>|</span>
            <a href="../index.html">返回首页</a>
            <span>|</span>
            <a href="perInfo.html">个人信息</a>
            <span>|</span>
            <a onclick="exitLogin()" style="cursor: pointer">退出登录</a>
        </div>
    </div>
</div>

<table width="95%" border="1" cellspacing="" cellpadding="5">
    <thead>
    <tr>
        <th>商品名称</th>
        <th>单价（元/斤）</th>
        <th>数量</th>
        <th>小计（元）</th>
    </tr>
    </thead>
    <tbody id="listBody">

    </tbody>


    <!--     循环区
    <tr>
        <td align="left" width="400">
            <span><img src="${pageContext.request.contextPath}/images/goods/${gwc.pic}" width="100px"
                       height="100px"/></span>
            <span style="vertical-align: top">${gwc.gname}</span></td>
        <td align="center" width="100">${gwc.price}</td>
        <td align="center" width="70">${gwc.num}</td>
        <td align="center" width="60">${gwc.price * gwc.num}</td>
    </tr>-->

    <!--    不循环区    -->
    <tbody id="messBody">
    <tr>
        <td colspan="7">
            <div id="UUser">

            </div>

            <div class="right" align="right">
                <a href="gwc.html">返回购物车</a>
            </div>
            <div class="right" align="right">                        <!-- 结算页面 -->
                总计： <span style="color:red ;font-weight:bold" id="totalPrice">0</span>&nbsp;&nbsp;¥
                <!--                <a href="  ">确认订单</a>-->
                <div id="toPayDiv" style="float: right">
                </div>
            </div>
            <div>&nbsp;</div>
            <div>&nbsp;</div>
        </td>
    </tr>
    </tbody>
</table>
</body>

<script src="../file/js/jquery-3.4.1.min.js" type="text/javascript"></script>
<script src="../file/js/jquery-ui.min.js" type="text/javascript"></script>
<script src="../file/js/slide.js" type="text/javascript"></script>

<script>
    $(function () {
        ifLogin();
        showAll();
    })

    function ifLogin() {
        //开始发送请求 验证用户是否登录
        $.ajax({
            url: "/ifLogined",
            type: "POST",
            success: function (data) {
                console.log(data);
                let str = '';
                if (data.code == 200) {
                    str += '<a href="../loginPage.html" title="您好！请登录">您好！请登录</a>';
                    str += '<a href="../reg.html" title="免费注册">免费注册</a>';

                } else {
                    str += '<a href="perInfo.html"> 【' + data.memberinfo.nickname + '】</a>';
                }
                //放入进去上面空的地方
                $(".login-info").html(str);

                let str2 =
                    `
                    <div>&nbsp;</div>
                    <div>用户：${data.memberinfo.nickname}</div>
                    <div>电话联系：${data.memberinfo.tel}</div>
                    <div>邮箱联系：${data.memberinfo.email}</div>
                    <div>收货地址：${data.memberinfo.address}</div>
                    <div><a href="perInfo.html">点击更换收货信息</a></div>`
                $("#UUser").html(str2);
            }
        })
    };
    function exitLogin() {
        $.ajax({
            url: "/exitLogin" ,
            type: "GET",
            success: function () {
                location.href="../index.html";
            }
        })
    };

    function showAll() {
        $.ajax({
            url: "/user/showAllGwc",
            type: "GET",
            success: function (data) {
                console.log(data);
                let str = '';
                totalPrice = 0;
                for (let i = 0; i < data.length; i++) {
                    totalPrice += (data[i].price * data[i].num);
                    str +=
                        `<tr>
                            <td align="left" width="400">
                                <span><img src="../file/images/goods/${data[i].pic}" width="100px"height="100px"/></span>
                                <span style="vertical-align: top">${data[i].gname}</span></td>
                            <td align="center" width="100">${data[i].price}</td>
                            <td align="center" width="70">${data[i].num}</td>
                            <td align="center" width="60">${data[i].price * data[i].num}</td>
                        </tr>`;
                }
                $("#totalPrice").html(totalPrice);
                $("#listBody").html(str);

                let str2 = '<a href="/user/toPay.html#' + totalPrice + '">&nbsp;&nbsp;&nbsp;提交订单</a>';
                $("#toPayDiv").html(str2);

            }
        })
    };

</script>
</html>